#!/bin/bash

# Query data from Elasticsearch
queryData() {
    result=$(curl -s -XPOST 'http://localhost:9200/tai-article/_doc/_search' -H 'Content-Type: application/json' -d"
{
    \"query\": {
        \"term\": {
            \"_spider_name.keyword\": \"$1\"
        }
    }
}
")
    # echo "Queried $1 articles: "
    echo $result | jq -r -c ."hits.total.value" | xargs echo "Queried $1 articles: "
    # echo hits list
    echo $result | jq -r -c ."hits.hits" | jq -r -c ."[]._source.title" | xargs echo -n "$1\n"
}

queryData $1